<template>
    <div class="searchOne">
      <div class="searchTop">
        <div class="back" @click="back">
          <span></span>
        </div>
        <input type="text" placeholder="防晒" ref="sel" @focus="nulls" @input="Lenovo">
        <div class="search" @click="searchs">搜索</div>
      </div>
      <router-view></router-view>
      <div class="hisAhot" v-for="(item, key) in searchList" :key = key>
        <p :class="item.searchClass">
          <img v-lazy="item.icons" alt="">
          <span>{{item.title}}</span>
          <img  class="del" @click="deletes" v-lazy="item.del" alt="" >
        </p>
        <span class="inputof"
              @click="addses(val)"
              v-for="(val, index) in item.hisAndhot"
              :key = index>{{val}}</span>
      </div>
    </div>
</template>

<script>
    export default {
        name: "search01",
      data(){
          return{
            searchList:[
              {title: '搜索历史',icons:require('./icons/time.png'),hisAndhot:['毛巾'],del:require('./icons/delete.png'),searchClass: 'Personalized'},
              {title:'热搜',
                icons:require('./icons/fire.png'),
                hisAndhot:['电风扇','话费充值','清凉油','抽纸','牙膏','空调','凉席','绿植','饮用水'],
                searchClass:'HotBot'}
              ]
          }
      },
      methods:{
        back(){
          this.$router.push({path:'./search01'});
          this.$router.push({path:'/index/auth'});
        },
        // 当点击搜索时跳转到联想搜索界面
        Lenovo(){
          this.$router.push({path:'./searchLenovo'});
          this.$bus.$on('lenovo', (one) =>{
            one();
          })
        },
        addses(val){
           this.$refs.sel.value = val;
        },
        // 当点击清空历史时清空数据的数组
        deletes(){
          this.searchList[0].hisAndhot = []
        },
        // 当搜索栏获取焦点时清空吧
        nulls(){
          this.$refs.sel.placeholder = '';
        },
        searchs(){
          this.$router.push({path:'./searchTwo'});
          let inputValue = this.$refs.sel.value;
          if(inputValue !== '' && inputValue !== '防晒'){
            this.searchList[0].hisAndhot.push(inputValue);
        }
          this.$refs.sel.value = '';
          this.$refs.sel.placeholder = '';
          console.log(this.searchList[0].hisAndhot);
        },
      },
      created() {

      },
      mounted() {
        if(this.$refs.sel.value === ''){
          this.$router.push({path:'./search01'});
        }
      }
    }
</script>

<style scoped lang="scss">
.searchOne{
  position: absolute;
  z-index: 999;
  width: 100vw;
  height: 100vh;
  background: url("./icons/1c5ba523b685c564.png") no-repeat  0 0;
  background-size: 100% 100%;
  box-sizing: border-box;
  padding: 35px 50px;
  overflow: hidden;
  .searchTop{
    height: 130px;
    display: flex;
    .back{
      line-height: 150px;
      width: 85px;
      text-align: left;
      span{
        display: inline-block;
        width: 50px;
        height: 50px;
        border: solid 1px #666;
        border-bottom: none;
        border-left: none;
        transform: rotate(225deg);
      }
    }
    input{
      flex: 1;
      height: 120px;
      border-radius: 70px;
      background: url("./icons/query.png") no-repeat 35px center #f2f2f2;
      background-size: 50px 50px;
      border: none;
      font-size: 40px;
      text-indent: 120px;
      outline: none;
    }
    .search{
      width: 160px;
      text-align: right;
      line-height: 120px;
      color: #333;
    }
  }
  .hisAhot{
    margin-top: 90px;
    p{
      margin: 0;
      display: flex;
      font-size: 45px;
      line-height: 45px;
      padding-bottom: 30px;
      img{
        width: 45px;
        height: 45px;
      }
      span{
        flex: 1;
        text-indent:24px;
      }
    }
    .HotBot{
      width: 120%;
      del{
        display: none;
      }
    }
  }
  .inputof{
    display: inline-block;
    padding: 20px 35px;
    background: #f2f2f2;
    color: #818181;
    border-radius: 50px;
    font-size: 42px;
    margin: 30px;
  }
}
</style>
